#ifndef _CNUM_NUM_CALC_H_
#define _CNUM_NUM_CALC_H_

#include "Result.h"
#include "Function.h"

/**
 * This class defines numerical methods for calculating x so that f(x)=0 with a given error threshold.
 */
class NumCalc {
public:
    static const int VERBOSITY_NONE = 0;
    static const int VERBOSITY_TEXT = 1;
    static const int VERBOSITY_CSV = 2;
    /**
     * Calculates x so that f(x)=0 using the Bisection method.
     *
     * @param a beginning of the interval to be considered
     * @param b end of the interval to be considered
     * @param precision the highest error value to be considered valid. The 'error' field on the returned
     * result set will be lower than precision.
     * @param function the function to use as f in the calculations
     * @param verbosity the level of verbosity on each iteration. can be VERBOSITY_NONE, VERBOSITY_TEXT or VERBOSITY_CSV
     * @return a resultset with x, the error and iteration count.
     */
    static Result bisection(double a, double b, double precision, const Function& function, int verbosity = VERBOSITY_NONE);

    /**
     * Calculates x to that f(x)=0 using the Fixed Point Iteration method. If a suiting fi function is
     * provided, this works as the Newton method.
     *
     * @param initial the value of x where the iteration will begin
     * @param precision the highest error value to be considered valid. The 'error' field on the returned
     * result set will be lower than precision.
     * @param function the function to use as f in the calculations. @deprecated this is not used.
     * @param fi the function to use as fi in the calculations.
     * @param verbosity the level of verbosity on each iteration. can be VERBOSITY_NONE, VERBOSITY_TEXT or VERBOSITY_CSV
     * @return a resultset with x, the error and iteration count.
     */
    static Result fixedPoint(double initial, double precision, const Function& function, const Function& fi, int verbosity = VERBOSITY_NONE);

    /**
     * Calculates x to that f(x)=0 using Bisection and the Newton method.
     *
     * @param a beginning of the interval to be considered
     * @param b end of the interval to be considered
     * @param precision the highest error value to be considered valid. The 'error' field on the returned
     * result set will be lower than precision.
     * @param function the function to use as f in the calculations.
     * @param fi the function to use as fi in the calculations.
     * @param verbosity the level of verbosity on each iteration. can be VERBOSITY_NONE, VERBOSITY_TEXT or VERBOSITY_CSV
     * @return a resultset with x, the error and iteration count.
     */
    static Result binewton(double a, double b, double precision, const Function& function, const Function& fi, int verbosity = VERBOSITY_NONE);
};

#endif
